<div ng-controller="Customer_ListC">
    <div class="bg-light lter b-b wrapper-md" id="widtha">
        <h1 class="m-n font-thin h3">客户列表</h1>
    </div>
    <div class="wrapper-md" style="text-align: center;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12" style="float: right">
                    <button class="btn btn-sm btn-default" ng-click="add()">
                        <i class="fa fa-plus text"></i>
                        <span class="text">添加</span>
                    </button>
                    <a class="btn btn-sm btn-default" href="/api/Customer/ExpCustomer">
                        <i class="fa fa-cloud-download text"></i>
                        <span class="text">全部导出</span>
                    </a>
                </div>
                <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 input-group" id="scrolll" style="overflow-x: scroll;">
                    <div class="input-group">
                        <span class="input-group-addon">模糊查找</span>
                        <input style="min-width: 100px" type="text" class="form-control" id="findname" placeholder="请输入名称或联系人" ng-model="findname">
                        <span class="input-group-addon">按状态查找</span>
                        <select class="form-control" id="typename" ng-model="typename" style="min-width: 100px">
                            <option value="">请选择状态</option>
                            <option value="0">等待审批</option>
                            <option value="2">通过</option>
                            <option value="3">驳回</option>
                        </select>
                        <span class="input-group-addon">开始时间:</span>
                            <input type="date" class="form-control" placeholder="按日期查找" ng-model="qTime">
                        <span class="input-group-addon">结束时间:</span>
                            <input type="date" class="form-control" placeholder="按日期查找" ng-model="qTime1">
                        <span class="input-group-btn">
                        <button class="btn btn-default" type="button" ng-click="find()">查找</button>
                        </span>
                    </div>
            </div>
            <div class="table-responsive">
                <table id="example1" class="table table-striped b-t b-light table-bordered">
                    <thead>
                    <tr>
                        <th style="text-align: center;">名称</th>
                        <th style="text-align: center;">地区</th>
                        <th style="text-align: center;">地址</th>
                        <th style="text-align: center;">备注</th>
                        <th style="text-align: center;">信誉</th>
                        <th style="text-align: center;">创建人</th>
                        <th style="text-align: center;">状态</th>
                        <th style="text-align: center; ">创建时间</th>
                        <th style="text-align: center;">审批时间</th>
                        <th style="text-align: center;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr ng-repeat="item in pageData.Data">
                        <td style="width: 10%">{{item.ShortName}}</td>
                        <td style="width: 11%">{{item.District.FillName}}</td>
                        <td style="width: 10%">{{item.Address}}</td>
                        <td style="width: 10%">{{item.Remarks}}</td>
                        <td style="width: 10%">{{item.CreditScore}}</td>
                        <td style="width: 10%">{{item.ClientManager.Name}}</td>
                        <td style="width: 10%">
                            <span ng-if="item.ApprovalState == 0">等待审批</span>
                            <span ng-if="item.ApprovalState == 1">审批中</span>
                            <span ng-if="item.ApprovalState == 2">通过</span>
                            <span ng-if="item.ApprovalState == 3">驳回</span>
                        </td>
                        <td style="width: 9%">
                            {{item.CreateTime | limitTo:16}}
                        </td>
                        <td style="width: 10%">
                            {{item.Record |limitTo:17 | limitTo:-16}}
                        </td>
                        <td style="width: 10%">
                            <button class="btn btn-sm btn-default" ng-if="item.ApprovalState==0" ng-click="$state.go('app.Customer_Confirm', { 'id': item.Id,'from':0 })">
                                <i class="fa fa-gears text"></i>
                                <span class="text">处理</span>
                            </button>
                            <button class="btn btn-sm btn-default" ng-if="item.ApprovalState!=0" disabled="disabled">
                                <i class="fa fa-gears text"></i>
                                <span class="text">处理</span>
                            </button>
                            <button class="btn btn-sm btn-default" ng-click="$state.go('app.Customer_Edit', { 'id': item.Id })">
                                <i class="fa fa-gears text"></i>
                                <span class="text">管理</span>
                            </button>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <!--<div class="panel-heading" ng-include="'/htm/tpl/Supplier/Paging.html'"></div>-->
                <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
                <div class="panel-heading text-right">
                    <b>客户总计:</b>
                    <b>{{pageData.Total}}</b>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module('app')//非标优惠
    .controller("Customer_ListC", function($scope, $state, $http,toSave) {
            $scope.pageData = {};
            $scope.pageData.Page = 0;
            $scope.typename = "";
            $scope.qTime=null;
            $scope.qTime1=null;
            $scope.pageData.Rows = $scope.defPageRows;
            //
            $scope.getData = function(p, r) {
//                console.log([$scope.pageData.Page + 1, p, r, $scope.pageData.Page, $scope.pageData.Total / $scope.pageData.Rows]);
                if (p) {
                    p = p < 1 ? 1 : p;
                } else p = 1;
                if (r) {
                } else r = $scope.defPageRows;
                toSave.save_pages_lis(p,r);//保存当前页码和条数

                $http({
                        url: "/api/Customer/List",
                        method: "GET",
                        params: { page: p, rows: r, like: $scope.findname,state:$scope.typename,startTime: $scope.qTime,endTime:$scope.qTime1}
                    })

                    .then(function(res) {

                        $scope.pageData = res.data;
                        console.log($scope.pageData);
                    }, function(error) {
                        if (error) {
                            alert("数据获取失败");
                        }
                    });
                console.log($scope.qTime+"..."+$scope.qTime1)
            };
         if ($('#widtha').width() <= 550) {
             $('#scrolll').removeClass('input-group')
         }
            $scope.getData(toSave.get_pages());
            $scope.add = function() {
                $state.go("app.Customer_Add");
            };
            $scope.testt = function(item) {
                return item + "";
            };
            $scope.find = function () {
                $scope.getData(1, $scope.pageData.Rows);
                // $scope.save_change();
                localStorage.setItem('c',$scope.typename);
                toSave.save_inputs();//点击查询先保存input里面的值
                console.log(toSave.get_inputs('findname'));
            };  
     //        $scope.save_change=function(){
     //               console.log($scope.typename);
     //               localStorage.setItem('c',$scope.typename);
     // };
             $scope.get_change=function(){
                var id
                 id=localStorage.getItem('c');
                 return id
             }
            
            if (toSave.get_inputs('findname') || $scope.get_change()!='' ) {
                    $scope.findname=toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                    $scope.typename=localStorage.getItem("c");
                    console.log($scope.typename);
                    $scope.getData(toSave.get_pages(), toSave.get_lis());
                }else{
                    $scope.getData(1, $scope.pageData.Rows);
                }

        })

</script>
<script src="js/services/toSave.js"></script>
